function ajaxSubmitForm(form, resultDivId) {
	form = document.getElementById(form);
	var elements = form.elements;
	var element;
	var i;
	var postContent = "";
	for (i = 0; i < elements.length; ++i) {
		var element = elements[i];
		if (element.type == "text" || element.type == "textarea"
				|| element.type == "hidden") {
			postContent += encodeURIComponent(element.name) + "="
					+ encodeURIComponent(element.value) + "&";
		} else if (element.type == "select-one"
				|| element.type == "select-multiple") {
			var options = element.options, j, item;
			for (j = 0; j < options.length; ++j) {
				item = options[j];
				if (item.selected) {
					postContent += encodeURIComponent(element.name) + "="
							+ encodeURIComponent(item.value) + "&";
				}
			}
		} else if (element.type == "checkbox" || element.type == "radio") {
			if (element.checked) {
				postContent += encodeURIComponent(element.name) + "="
						+ encodeURIComponent(element.value) + "&";
			}
		} else if (element.type == "file") {
			if (element.value != "") {
				postContent += encodeURIComponent(element.name) + "="
						+ encodeURIComponent(element.value) + "&";
			}
		} else {
			postContent += encodeURIComponent(element.name) + "="
					+ encodeURIComponent(element.value) + "&";
		}
	}
	// alert(postContent);
	ajaxSubmit(form.action, form.method, postContent,resultDivId);
}

function ajaxSubmit(url, method, postContent, resultDivId) {
//	var loadingDiv = document.getElementById('loading');
//	window.setTimeout(function() {
//		loadingDiv.innerText = "Loading.";
//		loadingDiv.style.display = "";
//	}, 1000);
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp) {
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
				if (resultDivId) {
					document.getElementById(resultDivId).innerHTML = xmlhttp.responseText;
				} else {
					var result = document.createElement("DIV");
					result.style.border = "1px solid #363636";
					result.innerHTML = xmlhttp.responseText;
					document.body.appendChild(result);
				}
				//loadingDiv.innerHTML = "Submit finnished!";
			}
		};
		if (method.toLowerCase() == "get") {
			xmlhttp.open("GET", url + "?" + postContent, true);
			xmlhttp.send(null);
		} else if (method.toLowerCase() == "post") {
			xmlhttp.open("POST", url, true);
			xmlhttp.setRequestHeader("Content-Type",
					"multipart/form-data");
			xmlhttp.send(postContent);
		}
	} else {
		loadingDiv.innerHTML = "Can't create XMLHttpRequest object, please check your web         browser.";
	}
}